/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.farent.solutions.plugins.stripes.hyperstripes.mock;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletContext;
import net.sourceforge.stripes.mock.MockServletContext;

/**
 *
 * @author user
 */
public class HSMockServletContext extends MockServletContext implements ServletContext
{

    public HSMockServletContext(String contextName) {
        super(contextName);
    }

    @Override
    public InputStream getResourceAsStream(String name) {
        try {
            if (name.endsWith("web.xml")) {
                return getTestWebXMLInputStream();
            }
            return super.getResourceAsStream(name);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(HSMockServletContext.class.getName()).log(Level.SEVERE, null, ex);
        } catch (URISyntaxException ex) {
            Logger.getLogger(HSMockServletContext.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    private InputStream getTestWebXMLInputStream() throws FileNotFoundException, URISyntaxException {
        URI uri = getClass().getResource("/web.xml").toURI();
        File file = new File(uri);
        return new FileInputStream(file);
    }
}
